﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'usp_reporteComprobanteRecepcion')
	BEGIN
		DROP  Procedure  usp_reporteComprobanteRecepcion
	END

GO

CREATE Procedure usp_reporteComprobanteRecepcion

 @idComprobantePresentacion as int
 
AS


DELETE FROM TMP_reporteComprobanteRecepcion

INSERT INTO TMP_reporteComprobanteRecepcion
SELECT     dbo.ComprobantePresentacion.ComprobantePresentacionId, dbo.ComprobantePresentacion.ComprobantePresentacionFecha, OSXP.Descripcion, 
                      dbo.Persona.PersonaApellido + ', ' + dbo.Persona.PersonaNombre as NombreEmpleado, 
                      dbo.DetalleComprobantePresentacion.DetalleComprobantePresentacionTotalFacturado, 
                      dbo.DetalleComprobantePresentacion.DetalleComprobantePresentacionCantidadRecetas, 
                      dbo.DetalleComprobantePresentacion.DetalleComprobantePresentacionACargoObraSocial, dbo.Farmacia.FarmaciaNombre, dbo.Farmacia.FarmaciaRazonSocial
FROM         dbo.ComprobantePresentacion INNER JOIN
                      dbo.DetalleComprobantePresentacion ON 
                      dbo.ComprobantePresentacion.ComprobantePresentacionId = dbo.DetalleComprobantePresentacion.ComprobantePresentacionId INNER JOIN
                      dbo.[ComboBox ObraSocialXPlan] AS OSXP ON dbo.DetalleComprobantePresentacion.ObraSocialXPlanId = OSXP.ObraSocialXPlanId INNER JOIN
                      dbo.Empleado ON dbo.ComprobantePresentacion.EmpleadoId = dbo.Empleado.EmpleadoId INNER JOIN
                      dbo.Persona ON dbo.Empleado.PersonaId = dbo.Persona.PersonaId INNER JOIN
                      dbo.Farmacia ON dbo.ComprobantePresentacion.FarmaciaId = dbo.Farmacia.FarmaciaId
 WHERE dbo.ComprobantePresentacion.ComprobantePresentacionId = @IdComprobantePresentacion
 
 SELECT * FROM TMP_reporteComprobanteRecepcion